<template>
  <div>
    <PageTemplate>
      <div slot="content">
        <PageEditCollapse :is-search="false" :default-collapse="true">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 200px;">{{$t('cm.baseinfo')}}</div>
          </div>
          <div>
            <!-- 表单 -->
            <el-form
              :model="standard"
              label-position="right"
              label-width="150px"
              class="page-edit-colllapse-form"
              :rules="rules"
              ref="standard"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_Code')" prop="subjectCode">
                    <span>{{standard.subjectCode}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_Name')" prop="subjectName">
                    <span>{{standard.subjectName}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_year')" prop="year">
                    <span>{{standard.year}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_level')" prop="subjectType">
                    <span>{{subjectTypeMap}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.standard_editor')" prop="editor">
                    <span>{{editorMap}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_deptName')" prop="deptName">
                    <span>{{deptNameMap}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_startTime')" prop="startTime">
                    <span>{{standard.startTime}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_endTime')" prop="endTime">
                    <span>{{standard.endTime}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.standard_finishName')" prop="finishName">
                    <span>{{finishNameMap}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.subject_User')" prop="subjectUser">
                    <span>{{standard.subjectUser}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sri.standard_publish')" prop="publish">
                    <span>{{publishMap}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </PageEditCollapse>
        <el-row class="row-empty-10"></el-row>
        <el-row>
          <el-button type="primary" @click="toList">{{$t('cm.return')}}</el-button>
        </el-row>
      </div>
    </PageTemplate>
  </div>
</template>

<script>
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import PageTemplate from '@/components/common/PageTemplate'
import PageEditCollapse from '@/components/common/PageEditCollapse'
import FileUploadMeeting from '@/components/common/FileUploadMeeting'
import HasBtn from '@/mixins/HasBtn'
import { mapState } from 'vuex'
import { COMMON } from '@/utils/commonUtil'
import api_sri from '@/api/api_sri'
import sys_manage from '@/api/sys_manage'
import PersonSelect from '@/components/asc/PersonSelect'

const vailSubjectUserName=(rule,value,callback)=>{
  if(document.getElementById("subjectUser").value) {
    callback();
  }else{
    callback(new Error("必填项"));
  }
};

export default {
  components: {
    PageTemplate, PageEditCollapse, PersonSelect, FileUploadMeeting
  },
  data () {
    return {
      standard: {
        id: null,
        subjectCode: null,
        subjectName: null,
        year: null,
        subjectType: null,
        subjectUser: null,
        editor: null,
        deptId: 11,
        deptName: null,
        startTime: null,
        endTime: null,
        finishId: 1,
        finishName: null,
        publish: null
      },
      subjectDepts: [],
      levels:[],
      finishNames:[],
      editors:[],
      rules: {
        subjectCode: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        subjectName: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        year: [
          { required: true, message: '必填项,且为整数',  trigger: 'blur' }
        ],
        subjectUser: [
          { required: true, validator: vailSubjectUserName, trigger: 'blur' }
        ],
        deptName: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        endTime: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        finishName: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        publish: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        editor: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.sysDictLoadByPaging();
    if (this.$router.history.current.params.id !== Constant.NEW_PARAMS) {
      this.sriGainStandardGet(this.$router.history.current.params.id)
    }
  },
  methods: {
    sriGainStandardGet (id) {
      api_sri.sriGainStandardGet({ id }, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.standard = result.data
        } else {
          // _this.$t('cm.tips')
          ALERT.error(result.msg)
        }
      })
    },
    sysDictLoadByPaging () {
      sys_manage.sysDictLoadByPaging({dictGroupKey: 'achievement_profession_dept'}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.subjectDepts = result.data
        } else {
          ALERT.error(result.msg)
        }
      })
      sys_manage.sysDictLoadByPaging({dictGroupKey: 'standard_level'}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.levels = result.data
        } else {
          ALERT.error(result.msg)
        }
      })
      sys_manage.sysDictLoadByPaging({dictGroupKey: 'standard_responsible_unit'}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.finishNames = result.data
        } else {
          ALERT.error(result.msg)
        }
      })
      sys_manage.sysDictLoadByPaging({dictGroupKey: 'chief_less_editor'}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.editors = result.data
        } else {
          ALERT.error(result.msg)
        }
      })
    },
    
    toList () {
      COMMON.routerTo(Constant.ROUTE_SRI_GAIN_STANDARD.index, this.$router)
    }
  },
  mounted () {
  },
  computed: {
    subjectTypeMap () {
      let ft = ''
      this.levels.forEach(item => {
        if (this.standard.subjectType === item.dictKey) {
          ft = item.dictText
        }
      })
      return ft
    },

    editorMapMap () {
      let ft = ''
      this.editors.forEach(item => {
        if (this.standard.editor === item.dictKey) {
          ft = item.dictText
        }
      })
      return ft
    },
    
    deptNameMap () {
      let ft = ''
      this.subjectDepts.forEach(item => {
        if (this.standard.deptName === item.dictKey) {
          ft = item.dictText
        }
      })
      return ft
    },

    finishNameMap () {
      let ft = ''
      this.finishNames.forEach(item => {
        if (this.standard.finishName === item.dictKey) {
          ft = item.dictText
        }
      })
      return ft
    },

    publishMap() {
      let ft = '';
      if (this.standard.publish === 'Y')
        ft = '是';
      else
        ft = '否';
      return ft
    }
 
  }
}
</script>

<style lang="scss">
</style>
